from django.db import models

# Create your models here.

class Home(models.Model):
    img = models.CharField(max_length=256)
    name = models.CharField(max_length=64)
    trackid = models.CharField(max_length=32)

    class Meta:
        abstract = True

class Wheel(Home):
    class Meta:
        db_table = 'axf_wheel'

class Nav(Home):
    class Meta:
        db_table = 'axf_Nav'

class MustBuy(Home):
    class Meta:
        db_table = 'axf_mustbuy'

class Shop(Home):
    class Meta:
        db_table = 'axf_shop'

class MainShow(models.Model):
    trackid = models.CharField(max_length=10)
    name = models.CharField(max_length=20)
    img = models.CharField(max_length=100)
    categoryid = models.CharField(max_length=10)
    brandname = models.CharField(max_length=20)

    img1 = models.CharField(max_length=100)
    childcid1 = models.CharField(max_length=10)
    productid1 = models.CharField(max_length=10)
    longname1 = models.CharField(max_length=50)
    price1 = models.CharField(max_length=10)
    marketprice1 = models.CharField(max_length=10)

    img2 = models.CharField(max_length=100)
    childcid2 = models.CharField(max_length=10)
    productid2 = models.CharField(max_length=10)
    longname2 = models.CharField(max_length=50)
    price2 = models.CharField(max_length=10)
    marketprice2 = models.CharField(max_length=10)

    img3 = models.CharField(max_length=100)
    childcid3 = models.CharField(max_length=10)
    productid3 = models.CharField(max_length=10)
    longname3 = models.CharField(max_length=50)
    price3 = models.CharField(max_length=10)
    marketprice3 = models.CharField(max_length=10)

    class Meta:
        db_table='axf_mainshow'

class FoodTypes(models.Model):
    typeid = models.CharField(max_length=120)
    typename = models.CharField(max_length=120)
    childtypenames = models.CharField(max_length=120)
    typesort = models.CharField(max_length=120)
    class Meta:
        db_table = 'axf_foodtypes'
class Goods(models.Model):
    # 商品id
    productid = models.CharField(max_length=10)
    # 商品图片
    productimg = models.CharField(max_length=150)
    # 商品名称
    productname = models.CharField(max_length=50)
    # 商品长名称
    productlongname = models.CharField(max_length=100)
    # 是否精选
    isxf = models.NullBooleanField(default=False)
    # 是否买一赠一
    pmdesc = models.CharField(max_length=10)
    # 规格
    specifics = models.CharField(max_length=20)
    # 价格
    price = models.CharField(max_length=10)
    # 超市价格
    marketprice = models.CharField(max_length=10)
    # 组id
    categoryid = models.CharField(max_length=10)
    # 子类组id
    childcid = models.CharField(max_length=10)
    # 子类组名称
    childcidname = models.CharField(max_length=10)
    # 详情页id
    dealerid = models.CharField(max_length=10)
    # 库存
    storenums = models.IntegerField()
    # 销量
    productnum = models.IntegerField()

    class Meta:
        db_table = 'axf_goods'

class User(models.Model):
    username = models.CharField(max_length=64)
    email = models.CharField(max_length=64)
    password = models.CharField(max_length=256)
    icon = models.ImageField(upload_to='%Y/%m/%d/img')
    active = models.BooleanField(default=0)
    is_delete = models.BooleanField(default=0)
    # u_token = db.Column(db.String(256))
    u_token = models.CharField(max_length=256,default='')

    class Meta:
        db_table = 'axf_user'

class Cart(models.Model):
    c_user = models.ForeignKey(User,on_delete=models.PROTECT)
    c_goods  = models.ForeignKey(Goods,on_delete=models.PROTECT)
    c_goods_num = models.IntegerField(default=1)
    c_is_select = models.BooleanField(default=True)
    class Meta:
        db_table = 'axf_cart'

class Order(models.Model):
    o_user = models.ForeignKey(User,on_delete=models.PROTECT)
    o_price = models.FloatField(default=0)
    o_time = models.DateTimeField(auto_now=True)
    o_status = models.IntegerField(default=0)
    class Meta:
        db_table = 'axf_order'

class OrderGoods(models.Model):
    o_order = models.ForeignKey(Order,on_delete=models.PROTECT)
    o_goods = models.ForeignKey(Goods,on_delete=models.PROTECT)
    o_goods_num = models.IntegerField(default=1)

    class Meta:
        db_table = 'axf_ordergoods'